<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org" lang="cn">
<head>
    <title>扫码识别</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="qrcode.js"></script>
</head>
<body background="../测试.jpg"
      style="background-repeat:no-repeat;
               background-attachment:fixed;
               background-size:100% 100%;" >
<h1 id="qrCodeInfo" th:text="${qrCodeInfo}" style="display:none;">aaa</h1>
<h1 id="url" th:text="${url}" style="display:none;">aaa</h1>
<h1 id="authid" th:text="${qrCodeInfo.auth_id}" style="display:none;">aaa</h1>
<h2 class="main">二维码时效为3分钟，请及时扫码</h2>

<div id="qrcode" class="main" style="width:200px; height:150px; ">
</div>


<script type="text/javascript">
    // 制造二维码
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width : 200,
        height : 200
    });
    // 二维码制造函数
    function makeCode () {
        var elText = document.getElementById("qrCodeInfo");
        qrcode.makeCode(elText.textContent);
    }

    makeCode();

    // 发送POST请求跳转到指定页面
    function httpPost(URL, PARAMS) {
        var temp = document.createElement("form");
        temp.action = URL;
        temp.method = "post";
        temp.style.display = "none";

        for (var x in PARAMS) {
            var opt = document.createElement("textarea");
            opt.name = x;
            opt.value = PARAMS[x];
            temp.appendChild(opt);
        }

        document.body.appendChild(temp);
        temp.submit();

        return temp;
    }
    // 设置参数
    var elText = document.getElementById("authid");
    var params = {
        "auth_id": elText.textContent,
        // "bValue": 'b',
    };
    // httpPost("/a", params);

    // 设置定时轮询
    var xunhuan = setInterval("test()",10000);
    // setTimeout(clearInterval(xunhuan),300000);
    function test() {
        console.log(elText);
        $.post("/getAuth_status",
            {
                auth_id:elText.textContent
            },
            function(data,status){
                if (data == 1){
                    // window.location.href = "../index.html";
                    // httpPost("/hpbrowser", params);
                    // httpPost("http://10.195.28.24:9325/rehp", params);
                    window.location.href = document.getElementById("url").textContent;
                    clearInterval(xunhuan);
                }
                if (data == 2){
                    alert("患者拒绝授权");
                    clearInterval(xunhuan);
                    document.getElementById("qrcode").textContent = "患者拒绝授权!";
                }
            });
    };
</script>
</body>
</html>

<style>
    .main{
        text-align: center; /*让div内部文字居中*/
        background-color: #fff;
        border-radius: 20px;
        width: 400px;
        height: 350px;
        /*margin-top:15px;*/
        margin: auto;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
</style>